<?php
header ("Content-Type:text/xml");  
$user = "user";
$pass = "pass";
$dbname = "scheda_informativa";
try {
	error_reporting(E_ALL | E_STRICT);
	$db = new PDO('mysql:host=127.0.0.1;dbname='.$dbname, $user, $pass);
	$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$rs = $db->query("SELECT * FROM modulo WHERE pkid=5");
	foreach($rs->fetchAll(PDO::FETCH_ASSOC) as $row) {
		print  encode($row,"scheda_informativa",2);
	}
	$db = null;
} catch (PDOException $e) {
	print "Error!: " . $e->getMessage() . "<br/>";
	die();
}

function encode($data, $node, $depth) {
	$xml="";
	$xml .= str_repeat("\t", $depth);
	$xml .= "<$node>\n";
	foreach($data as $key => $val) {
		if(is_array($val) || is_object($val)) {
			$xml .= self::encode($val, $key, ($depth + 1));
		} else {
			$xml .= str_repeat("\t", ($depth + 1));
			$xml .= "<$key>" . htmlspecialchars($val) . "</$key>\n";
		}
	}
	$xml .= str_repeat("\t", $depth);
	$xml .= "</$node>\n";
	return $xml;
}

?>
